package com.example.fruitdb.controller;


import com.example.fruitdb.service.FruitService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/deleteFruit")
public class DeleteServlet extends HttpServlet
{
    private FruitService deleteService = new FruitService();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {

        //解析json数据
        String fruitID = request.getParameter("fruit[fruitId]");

        System.out.println("[deleteservice] "+fruitID);
        //调用service层的方法
        boolean res = deleteService.deleteFruit(Integer.parseInt(fruitID));

        //返回结果
        PrintWriter out = response.getWriter();
        if(res)
        {
            out.write("success");
        }else {
            out.write("fail");
        }




    }

}
